package cn.jszx.core.service.user;

import cn.jszx.core.bean.user.User;
import cn.jszx.core.dao.user.UserDao;
import cn.jszx.core.query.user.UserQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    UserDao userDao;

    /**
     * 插入数据库
     *
     * @return
     */
    public Integer addUser(cn.jszx.core.bean.user.User User) {
        return userDao.addUser(User);
    }

    /**
     * 根据主键查找
     */
    @Transactional(readOnly = true)
    public User getUserByKey(String id) {
        return userDao.getUserByKey(id);
    }

    @Transactional(readOnly = true)
    public User getSimpleUserByUsername(String username) {
        User user = userDao.getSimpleUserByUsername(username);
        user.setUsername(username);
        return user;
    }

    @Transactional(readOnly = true)
    public List<User> getUsersByKeys(List<String> idList) {
        return userDao.getUsersByKeys(idList);
    }

    /**
     * 根据主键删除
     *
     * @return
     */
    public Integer deleteByKey(String id) {
        return userDao.deleteByKey(id);
    }

    public Integer deleteByKeys(List<String> idList) {
        return userDao.deleteByKeys(idList);
    }

    /**
     * 根据主键更新
     *
     * @return
     */
    public Integer updateUserByKey(User user) {
        return userDao.updateUserByKey(user);
    }


    @Transactional(readOnly = true)
    public List<User> getUserList(UserQuery userQuery) {
        return userDao.getUserList(userQuery);
    }


}
